home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGBLER / WHIZZARD.LZH / ZPRINT.ASM < prev    next >
Assembly Source File  |  1984-07-12  |  7KB  |  273 lines

  1. COMMENT *
  2.  
  3.                  CLUBware  (tm)
  4.  
  5.       ZPRINT prints a character string on the screen starting
  6.           at the current cursor position.  After the string is
  7.           written to the screen the cursor position is updated
  8.           to just after the string.
  9.  
  10.            Copyright 1984 Rayhawk Automation N.W. Inc
  11.                   P.O. Box 1427
  12.                   Beaverton, Oregon   97075
  13.  
  14.  
  15.       Algorithm:
  16.           1) load type of crt display from 0000:463
  17.           2) load current position from 0000:0450
  18.           3) load count of characters to write
  19.           4) load string address
  20.           5) address the screen segment
  21.           6) move string to screen segment while synchronizing
  22.               with horizontal retrace
  23.           7) update cursor position
  24.  
  25.  
  26.       CALL    ZPRINT ( FLAG% , CHARACTER$ , ATTRIBUTE% )
  27.  
  28.           FLAG%       environment flag
  29.                   = 0 means under basic interpreter
  30.                   = 1 means under compiled basic not /O
  31.                   = 2 means under compiled basic with /O
  32.                   = 3 means under compiled business basic
  33.  
  34.           CHARACTER$  character string to write to screen
  35.  
  36.           ATTRIBUTE%  is the attribute to use with the string.
  37.                        07 is normal
  38.                        70 is reverse video
  39.                        01 is blue
  40.                   other definitions can be found
  41.                    in the technical reference manual or in
  42.                    the basic manual under the color statement
  43.                                           *
  44.  
  45. ;______________________________________________________________________________
  46.  
  47. ;  Normal assembly directives
  48.  
  49. CODE      SEGMENT PARA PUBLIC 'CODE'
  50.  
  51.       ASSUME  CS:CODE
  52.  
  53.       EXTRN   $PUTCPOS:FAR
  54.  
  55.       PUBLIC  ZPRINT
  56.  
  57. ATTRIBUTE      EQU  WORD PTR [BP+6] ; address of attribute on stack
  58.  
  59. STRING_DESC      EQU  WORD PTR [BP+8] ; address of string descriptor on stack
  60.  
  61. ENV_FLAG      EQU  WORD PTR [BP+10] ; address of environment flag on stack
  62.  
  63. ;______________________________________________________________________________
  64.  
  65. ZPRINT      PROC      FAR
  66.  
  67.       PUSH      BP               ; address parameters on stack
  68.       MOV      BP,SP
  69.  
  70.       PUSH      AX               ; save all registers used,
  71.       PUSH      BX
  72.       PUSH      CX
  73.       PUSH      DX
  74.       PUSH      DI
  75.       PUSH      SI
  76.       PUSH      ES
  77.  
  78.  
  79. ;      ...      0) load environment flag showing compiled or interpreted
  80.  
  81.       MOV      SI,ENV_FLAG           ; load address of environment flag
  82.       MOV      SI,WORD PTR [SI]     ; load flag itself
  83.  
  84.  
  85.  
  86. ;      ...      1) load type of crt display from 0000:463
  87.  
  88.       SUB      AX,AX              ; address system area
  89.       MOV      ES,AX
  90.  
  91.       MOV      DX,WORD PTR ES:[463h]      ; load address of display adapter
  92.       ADD      DX,6                 ; address crt status port
  93.  
  94.  
  95.  
  96. ;      ...      2) load current position from 0000:0450 if compiled
  97. ;              or from DS:[0056h] if interpreted
  98.  
  99.       CMP      SI,0               ; check environment flag
  100.       JNE      COMPILED
  101.  
  102.       MOV      CX,WORD PTR DS:[0056h]   ; load from basic space
  103.       XCHG      CL,CH            ; basic has it reversed
  104.       DEC      CL               ; basic starts count from 1
  105.       DEC      CH               ;  instead of zero
  106.       JMP      SHORT CALC_POSITION
  107.  
  108. COMPILED:
  109.       MOV      CX,WORD PTR ES:[450h]    ; load current position
  110.                        ;  from system space
  111. CALC_POSITION:
  112.       SUB      AH,AH            ; isolate row number in AX
  113.       MOV      AL,CH
  114.       MOV      BL,80            ; multiply row by 80 bytes per row
  115.       MUL      BL
  116.       SUB      CH,CH            ; add in column number
  117.       ADD      AX,CX
  118.  
  119.       MOV      DI,AX
  120.       SHL      DI,1               ; multiply by 2 to account
  121.                        ;  for attribute bytes
  122.  
  123. ;      ...      3) load count of characters to write
  124. ;             only 1 byte if interpreted
  125. ;              2 bytes if compiled
  126.  
  127.       MOV      BX,STRING_DESC       ; load address of string descriptor
  128.  
  129.       CMP      SI,0               ; running compiled?
  130.       JNE      NOT_INTERPRETED
  131.  
  132.       MOV      CL,BYTE PTR [BX]     ; load 1 byte count itself
  133.       SUB      CH,CH
  134.       INC      BX               ; bump to string address
  135.       JMP      SHORT LOAD_ADDRESS
  136.  
  137. NOT_INTERPRETED:
  138.       MOV      CX,WORD PTR [BX]     ; load 2 byte count itself
  139.       ADD      BX,2               ; bump to string address
  140.  
  141. LOAD_ADDRESS:
  142.  
  143. ;      ...      4) load string address
  144. ;               next two bytes if normal compiled
  145. ;            three bytes past if in business basic
  146.  
  147.       MOV      BX,WORD PTR [BX]     ; load offset of string
  148.  
  149.       CMP      SI,3
  150.       JNE      NOT_BUSINESS
  151.  
  152.       ADD      BX,3               ;  Support BBC String format
  153.  
  154. NOT_BUSINESS:
  155.  
  156.       MOV      SI,BX            ; move offset over
  157.  
  158.  
  159. ;      ...      4a) load the attribute to be used with the string
  160.  
  161.       MOV      BX,ATTRIBUTE           ; load address of the attribute
  162.       MOV      BH,BYTE PTR DS:[BX]  ; load the attribute itself
  163.  
  164.  
  165. ;      ...      5) address the screen segment
  166.  
  167.       MOV      AX,0B000h           ; screen seg for monochrome card
  168.       CMP      DX,03DAh           ; is this a graphic card?
  169.       JNE      MONOCHROME
  170.  
  171.       MOV      AX,0B800h           ; load screen seg for graphic card
  172.  
  173. MONOCHROME:
  174.  
  175.       MOV      ES,AX            ; address the screen buffer
  176.  
  177.  
  178. ;      ...      6) move string to screen while synchronizing
  179. ;              with horizontal retrace
  180.  
  181. DISPLAY_LOOP:
  182.       LODSB                ; load next character
  183.       MOV      BL,AL
  184.  
  185.       CLI
  186. HSYNC_WAIT1:
  187.       IN      AL,DX            ; check for horizontal retrace
  188.       TEST      AL,1
  189.       JNZ      HSYNC_WAIT1           ; wait for retrace
  190. HSYNC_WAIT2:
  191.       IN      AL,DX            ; check for horizontal retrace
  192.       TEST      AL,1
  193.       JZ      HSYNC_WAIT2           ; wait for retrace
  194.  
  195.       MOV      AX,BX
  196.       STOSW                ; store character and attribute
  197.       STI
  198.  
  199.       CMP      DI,4000
  200.       JL      NOT_OFF_PAGE
  201.       MOV      DI,0               ; start at top again
  202. NOT_OFF_PAGE:
  203.  
  204.       LOOP      DISPLAY_LOOP           ; repeat cx times
  205.  
  206.  
  207. ;      ...      7) update cursor position
  208.  
  209.       MOV      AX,DI            ; load current position
  210.       SHR      AX,1               ; discount attribute bytes
  211.       SUB      DX,DX            ; no sign in this division
  212.       MOV      BX,80            ; divide by nmbr of chars per row
  213.       DIV      BX
  214.       MOV      DH,AL            ; store row number
  215.                        ; column number already in DL
  216.       MOV      BH,0               ; assume page 0
  217.       MOV      AH,2               ; request new position
  218.       INT      10h
  219.  
  220.       XCHG      DH,DL            ; basic likes it reversed
  221.       INC      DL               ; basic starts count from 1
  222.       INC      DH               ;  instead of zero
  223.  
  224.       MOV      SI,ENV_FLAG           ; load address of environment flag
  225.       CMP      WORD PTR DS:[SI],0   ; examine flag
  226.       JE      NOT_COMPILED
  227.  
  228.       CMP      WORD PTR DS:[SI],3   ; business basic?
  229.       JE      RET_TO_BASIC
  230.  
  231.       CMP      WORD PTR DS:[SI],2   ; compiled with /O?
  232.       JE      WITH_SLASH_O
  233.  
  234.                                     ; FLAG = 1
  235.       MOV      WORD PTR DS:[87h],DX ; store screen address
  236.       JMP      SHORT RET_TO_BASIC
  237.  
  238.  
  239. WITH_SLASH_O:                                ; FLAG = 2
  240.       MOV      DI,SEG $PUTCPOS     ; address put cursor routine
  241.       MOV      ES,DI
  242.       MOV      DI,OFFSET $PUTCPOS
  243.       MOV      DI,WORD PTR ES:[DI+2]  ; load offset of cursor storage
  244.       MOV      WORD PTR DS:[DI],DX     ; store new cursor position
  245.       JMP      SHORT RET_TO_BASIC
  246.  
  247.  
  248. NOT_COMPILED:                                ; FLAG = 0
  249.       MOV      WORD PTR DS:[0056h],DX ; store new cursor position
  250.  
  251.  
  252. RET_TO_BASIC:                                ; FLAG = 3
  253.  
  254.  
  255.       POP      ES
  256.       POP      SI
  257.       POP      DI
  258.       POP      DX
  259.       POP      CX
  260.       POP      BX
  261.       POP      AX
  262.       POP      BP
  263.       RET      6
  264.  
  265.  
  266. ZPRINT      ENDP
  267.  
  268. ;______________________________________________________________________________
  269.  
  270. CODE      ENDS
  271.  
  272.       END
  273.